from Object3D import *
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from Image import *

class Texture():
	def __init__(self):
		self.textureList = []

	def loadTextures(self,fileName):
		#Load the image file
		file = open(fileName)
		data = file.tostring("raw", "RGBX", 0, -1)
		# array = [id, data, width, height]
		texture = [glGenTextures(1),data, file.size[0], file.size[1]]
		self.textureList.append(texture)
		return len(self.textureList)-1

	def bindTexture(self, index):
		texture = self.textureList[index]
		glBindTexture(GL_TEXTURE_2D, texture[0])
		#Load the Data into the Texture
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture[2], texture[3], 0, GL_RGBA, GL_UNSIGNED_BYTE, texture[1] )
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
		#glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
		#glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)

